package com.hns.can.mainte.web;

import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hns.can.base.entity.SysUserEntity;
import com.hns.can.common.domain.GridPage;
import com.hns.can.common.service.CommonInitParamService;
import com.hns.can.common.vo.CommonParamsVo;
import com.hns.can.common.web.BaseController;
import com.hns.can.mainte.service.BatteryStatusService;
import com.hns.can.mainte.vo.BatteryStatusVo;
import com.hns.frame.mybatis.Pagination;
import com.hns.tool.export.ExportUtil;
import com.hns.tool.pub.DateTool;

/**
 * 电池状态Controller
 * @author:zhangzq
 * @email:
 * @version Revision 2.0.0
 */
@Controller
@RequestMapping("/batteryStatus")
public class BatteryStatusController extends BaseController {
	
	final private String[] headerNames = new String[]{"车牌号","运营线路","所属机构","采集时间","总里程","车速","电池材料类型","电池状态","总电压","总电流","SOC值","最高单体电压","最高单体电压编号","最低单体电压","最低单体电压编号",
            "平均电压","压差","最高单体温度","最高单体温度编号","最低单体温度","平均温度","温差","充放电电流","电池箱最高温度"};
	final private String[] headerFields = new String[]{"licPltNo", "lineName", "organName", "rcrdTime", "totalMile", "spdOfMotVhi", "bteryMaterialType", "bterySt", "totalVtg", 
        "totalEltCrt", "soc", "highestBteryVtg","highestVtgBoxno","lowestBteryVtg","lowestVtgBoxno", "avrgBteryVtg", "vtgDiff", "highestTept","highestTeptBoxno", "lowestTept", "avrgBteryTept", "teptDiff", "chargeDischarEltCrt","bteryBoxHighestTept"};
	
    @Autowired
    private BatteryStatusService batteryStatusService;
    @Autowired
    private CommonInitParamService commonInitParamService;
    
    /**
     * 分页查询电池状态
     * @param params
     * @return
     * @throws Exception
     * @author:zhangzq
     * @email:
     */
    @RequestMapping("/searchBatteryStatus")
	@ResponseBody
    public Object searchBatteryStatus(CommonParamsVo params) throws Exception {
    	SysUserEntity user = this.getCurrentUser().getUser();
    	commonInitParamService.initParamsLimitCar(params, user, Arrays.asList("T_COMM_BTERY_MANAGE_STM_INFO"));
    	Pagination page = batteryStatusService.searchBatteryStatus(params);
        GridPage grid = new GridPage(page);
        return this.getReturnResult(grid);
    }
    
    /**
     * 导出电池状态Excel文件
     * @param params
     * @throws Exception
     * @author:zhangzq
     * @email:
     */
    @RequestMapping("/exportBatteryStatusExcel")
    public void exportBatteryStatusExcel(CommonParamsVo params,HttpServletResponse response) throws Exception {
        List<BatteryStatusVo> list = getBatteryStatusData(params);
        ExportUtil.exportFiles(Arrays.asList(headerNames), Arrays.asList(headerFields), list, response, "excel", "BatteryStatus"+DateTool.getCurrentSysDate("yyyyMMddHHmmss"), "电池状态数据");
    }
    
    /**
     * 导出电池状态Pdf文件
     * @param params
     * @throws Exception
     * @author:zhangzq
     * @email:
     */
    @RequestMapping("/exportBatteryStatusPdf")
    public void exportBatteryStatusPdf(CommonParamsVo params,HttpServletResponse response) throws Exception {
        List<BatteryStatusVo> list = getBatteryStatusData(params);
		ExportUtil.exportFiles(Arrays.asList(headerNames), Arrays.asList(headerFields), list, response, "pdf", "BatteryStatus"+DateTool.getCurrentSysDate("yyyyMMddHHmmss"), "电池状态数据");
    }
    
    /**
     * 查询电池状态用于导出
     * @param params
     * @return
     * @throws Exception
     * @author:zhangzq
     * @email:
     */
    private List<BatteryStatusVo> getBatteryStatusData(CommonParamsVo params) throws Exception {
    	SysUserEntity user = this.getCurrentUser().getUser();
    	commonInitParamService.initParamsLimitCar(params, user,Arrays.asList("T_COMM_BTERY_MANAGE_STM_INFO"));
        List<BatteryStatusVo> list = batteryStatusService.getBatteryStatusData(params);
        return list;
    }
    
    // DOIT: 2016-12-23 电池-续航里程分析
    
    /**
     * 查询soc数据
     * @param params
     * @return
     * @author:zhangzq
     * @email:
     */
    @RequestMapping("/socCharts")
	@ResponseBody
    public Object socCharts(CommonParamsVo params){
        SysUserEntity user = this.getCurrentUser().getUser();
        params.setCorpId(user.getCorpId());
        List<BatteryStatusVo> list = batteryStatusService.socCharts(params);
        return this.getReturnResult(list);
    }
    
    // DOIT: 2016-12-23 电池-电压电流图表
    
    /**
     * 查询电池电压数据
     * @param params
     * @return
     * @author:zhangzq
     * @email:
     */
    @RequestMapping("/voltageAnalysis")
    @ResponseBody
    public Object voltageAnalysis(CommonParamsVo params){
    	SysUserEntity user = this.getCurrentUser().getUser();
        params.setCorpId(user.getCorpId());
        List<BatteryStatusVo> list = batteryStatusService.voltageAnalysis(params);
        return this.getReturnResult(list);
    }
    
}

